The effect of this rule is to require that operands are appropriately parenthesized. Parentheses are important in this situation both for
readability of code and for ensuring that the behavior is as the developer intended.
Where an expression consists of either a sequence of only logical &&
or a sequence of logical ||
, extra
parentheses are not required.
Noncompliant code example
if (x == 0 && ishigh); // Noncompliant
if (x || y || z);
if (x || y && z); // Noncompliant
if (x && !y); // Noncompliant
if (is_odd(y) && x);
if ((x > c1) && (y > c2) && (z > c3));
if ((x > c1) && (y > c2) || (z > c3)); // Noncompliant
Compliant solution
if ((x == 0) && ishigh);
if (x || y || z);
if (x || (y && z));
if (x && (!y));
if (is_odd(y) && x);
if ((x > c1) && (y > c2) && (z > c3));
if ((x > c1) && ((y > c2) || (z > c3)));